//
//  QJShopDetailVC.m
//  QuanJieShopProject
//
//  Created by apple on 2018/1/31.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJShopDetailVC.h"
#import "QJShopDetailOneVC.h"
#import "QJShopDetailTwoVC.h"
#import "YFGoodsTypeView.h"
//登录界面
#import "QJLoginVC.h"
//订单预览界面
#import "QJPreviewOrderVC.h"

#import "YFShopDetailCell.h"
@interface QJShopDetailVC () <UIScrollViewDelegate>
{
    int _bugGoodsOrAddShop; // 0:立即购买 1:添加购物车
    
}
//滑动界面
@property (nonatomic, strong) UIScrollView *myScrollView;
@property (nonatomic, strong) QJShopDetailOneVC *shopVC;
@property (nonatomic, strong) QJShopDetailTwoVC *detailVC;
@property (nonatomic, strong) NSDictionary *detailDic;
/* 商品类型数组 */
@property (nonatomic, strong) NSArray<YFGoodsTypeModel *> *goodsTypeArr;
@property (nonatomic, strong) YFGoodsTypeView *typeView;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIButton *collectionBtn;
@property (nonatomic, strong) UIButton *shareBtn;

@end

@implementation QJShopDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 启动懒加载
    self.bottomView;
    
    //默认配置
    self.shopBtn.selected = YES;
    self.shopLabel.backgroundColor = YFColor_Red;
    self.detailBtn.selected = NO;
    self.detailLabel.backgroundColor = [UIColor whiteColor];
    self.buyCount = @"1";
    
    [self setupScrollViewAction];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavAlpha:YES];
    self.navigationController.navigationBarHidden = YES;
    [self dataRequestDetailAction];
    
    // 底部有34的安全距离
    // 测试
//    CGFloat height = 50;
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, UISCREEN_HEIGHT - height - 34, UISCREEN_WIDTH, height)];
//    view.backgroundColor = [UIColor blueColor];
//    [self.view addSubview:view];
    // 测试结束
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self setNavAlpha:NO];
    self.navigationController.navigationBarHidden = NO;

}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self.collectionBtn layoutButtonWithEdgeInsetsStyle:LLButtonStyleTextBottom imageTitleSpace:0];
    [self.shareBtn layoutButtonWithEdgeInsetsStyle:LLButtonStyleTextBottom imageTitleSpace:0];

    
}
- (IBAction)headerBtnClickAction:(UIButton *)sender {
    NSInteger tag = sender.tag;
    if (tag == 300) {
        //点击的返回按钮
        KPopViewControllerAction;
    }else if (tag == 301){
        //点击的是商品按钮
        self.shopBtn.selected = YES;
        self.shopLabel.backgroundColor = YFColor_Red;
        self.detailBtn.selected = NO;
        self.detailLabel.backgroundColor = [UIColor whiteColor];
        [_myScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }else{
        //点击的是详情按钮
        self.shopBtn.selected = NO;
        self.shopLabel.backgroundColor = [UIColor whiteColor];
        self.detailBtn.selected = YES;
        self.detailLabel.backgroundColor = YFColor_Red;
        [_myScrollView setContentOffset:CGPointMake(UISCREEN_WIDTH, 0) animated:YES];
    }
}

#pragma mark -- UIScrollView配置
- (void)setupScrollViewAction{
    if (IOS_VERSION < 11.0) {
        self.navTopHeight.constant = 20;
    }else{
        self.navTopHeight.constant = 0;
    }
    WEAKSELF
    //创建UIScrollView
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    //frame中的size指UIScrollView的可视范围
    scrollView.frame = CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT - 52-Height_NavBar);
    scrollView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:scrollView];
    self.myScrollView = scrollView;
    //设置UIScrollView的属性
    //设置UIScrollView的滚动范围（内容大小）
    scrollView.contentSize = CGSizeMake(UISCREEN_WIDTH * 2, UISCREEN_HEIGHT - 52-Height_NavBar);
    //隐藏水平滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    //用来记录scrollview的滚动位置(默认CGPointZero)
    scrollView.contentOffset = CGPointZero;
    //去掉弹簧效果
    scrollView.bounces = NO;
    //增加额外的滚动区域(上左下右)视图在scrollView中的位置(UIEdgeInsetsZero)
    //scrollView.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
    //代理方法
    scrollView.delegate = self;
    //指定控件是否只能在一个方向上滚动(默认为NO)
    scrollView.directionalLockEnabled = YES;
    //控制垂直方向遇到边框是否反弹(默认为NO,如果为YES，bounces也是YES)
    scrollView.alwaysBounceVertical = NO;
    //控制水平方向遇到边框是否反弹(默认为NO,如果为YES，bounces也是YES)
    scrollView.alwaysBounceHorizontal = NO;
    //控制控件是否整页翻动(默认为NO)
    scrollView.pagingEnabled = YES;
    //控制控件是否能滚动
    scrollView.scrollEnabled = YES;
    //指定滚动条在scrollerView中的位置
    //scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(2, 2, 2, 2);
    //设定滚动条的样式
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleDefault;
    
    //添加界面
    QJShopDetailOneVC *oneVC = [[QJShopDetailOneVC alloc]init];
    oneVC.view.frame = CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT - 52);
    _shopVC = oneVC;
    [scrollView addSubview:oneVC.view];
    oneVC.buyShopNumBlock = ^(NSInteger num) {
        weakSelf.buyCount = num;
    };
    oneVC.didSelectRow = ^(NSInteger row) {
        if (row == 1) {
            [self.typeView show];
        }
    };
    QJShopDetailTwoVC *twoVC = [[QJShopDetailTwoVC alloc]init];
    twoVC.view.frame = CGRectMake(UISCREEN_WIDTH, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT - 52);
    _detailVC = twoVC;
    [scrollView addSubview:twoVC.view];
    
}
#pragma mark -- UIScrollViewDelegate
//滚动视图减速完成，滚动将停止时，调用该方法。一次有效滑动，只执行一次
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"scrollViewDidEndDecelerating");
    //监控目前滚动的位置
    //[_myScrollView setContentOffset:CGPointMake(0, 500) animated:YES];
    CGPoint point = scrollView.contentOffset;
    CGFloat x = point.x;
    if (x == 0) {
        //商品按钮
        self.shopBtn.selected = YES;
        self.shopLabel.backgroundColor = RGB(41, 181, 237);
        self.detailBtn.selected = NO;
        self.detailLabel.backgroundColor = [UIColor whiteColor];
    }else if (x == self.view.frame.size.width){
        //详情按钮
        self.shopBtn.selected = NO;
        self.shopLabel.backgroundColor = [UIColor whiteColor];
        self.detailBtn.selected = YES;
        self.detailLabel.backgroundColor = RGB(41, 181, 237);
    }
}
#pragma mark -- 商品详情数据请求
- (void)dataRequestDetailAction{
    
    WEAKSELF
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:self.goodsID forKey:@"id"];
//    [dict setValue:@"5543" forKey:@"id"];
    
    NSLog(@"goodsID = %@", self.goodsID);
    [WWNetRequest fetchGoodsDetailWithParameters:dict success:^(id response) {

        NSLog(@"response 商品信息 = %@", response);
        NSDictionary *data = response[@"data"];
        self.detailDic = data[@"goods"];
        
        // 是否收藏
        NSString *collect = [NSString stringWithFormat:@"%@",self.detailDic[@"is_collect"]];
        if ([collect isEqualToString:@"0"]) {
            weakSelf.collectionBtn.selected = NO;
        }else{
            weakSelf.collectionBtn.selected = YES;
        }

        // 规格
        NSArray *typeArr = data[@"filter_spec"];
        if (typeArr.count) {
            self.hasAttribute = YES;
        }else {
            self.hasAttribute = NO;
        }
        NSMutableArray *tempTypeArr = [NSMutableArray array];
        for (NSDictionary *dict in typeArr) {
            // 外层model
            YFGoodsTypeModel *model = [YFGoodsTypeModel alloc];
            model.title = dict[@"name"];
            
            NSArray *subArr = dict[@"item"];
            
            NSMutableArray *tempArr = [NSMutableArray array];
            for (NSDictionary *subDict in subArr) {
                // 商品类型选择
                YFGoodsTypeSubModel *subModel = [[YFGoodsTypeSubModel alloc] initWithDictionary:subDict error:nil];
                subModel.state = @1; // 默认都是一般状态
                [tempArr addObject:subModel];
            }
            model.dataArr = tempArr;
            
            [tempTypeArr addObject:model];
        }
        self.typeView.goodsTypeArr = [NSArray arrayWithArray:tempTypeArr];
        
        
        
        // 不同规格组合,不同价格
        self.typeView.goodsPriceArr = nil;
        NSArray *goodsPriceArr = data[@"spec_goods_price"];
        NSMutableArray *tempPriceArr = [NSMutableArray array];
        if (goodsPriceArr.count) {
            for (NSDictionary *dict in goodsPriceArr) {
                YFGoodsPriceModel *model = [[YFGoodsPriceModel alloc] initWithDictionary:dict error:nil];
                [tempPriceArr addObject:model];
            }
        }
        self.typeView.goodsPriceArr = [NSArray arrayWithArray:tempPriceArr];
        
        
        // 给控制器赋值
        [_shopVC detailOneUpdateWithDic:response];
        [_detailVC detailTwoUpdateWithDic:response];
        [_typeView detailTypeUpdateWithDic:self.detailDic];

    } failure:^(NSDictionary *error) {
        NSLog(@"response 商品信息error = %@", error);

    }];
}

#pragma mark -- 底部功能按钮
- (IBAction)bottomBtnClickAction:(UIButton *)sender {
    NSInteger tag = sender.tag;
    switch (tag) {
        case 400:
        {
            [self shopCollectActionOrNot];
        }
            break;
        case 401:
        {
            [self jumpToShopCarAction];
        }
            break;
        case 402:
        {
            [self addShopToShopCarAction];
        }
            break;
        case 403:
        {
            [self buyGoodsAction];
        }
            break;
            
        default:
            break;
    }
}
#pragma mark -- 收藏、取消收藏
- (void)shopCollectActionOrNot{
    //判断是否登录
    NSString *token = [QJUserInfo getToken];
    if (!token) {
        [MBPHUD showAlertWithTitle:@"请先登录您的账号!"];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        KPushViewControllerAction(VC);
        return;
    }
    if (self.detailDic) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setObject:self.detailDic[@"id"] forKey:@"goodsid"];
        [dict setObject:self.detailDic[@"shopid"] forKey:@"shopid"];
        
        NSString *isCollect = [NSString stringWithFormat:@"%@",self.detailDic[@"is_collect"]];

        WEAKSELF
        if ([isCollect isEqualToString:@"0"]) {
            //执行收藏的方法
            [WWNetRequest fetchAddCollectWithParameters:dict success:^(id response) {
                //更新数据
                [weakSelf dataRequestDetailAction];
            } failure:^(NSDictionary *error) {
            }];
        }else{
            //执行取消收藏的方法
            [WWNetRequest fetchDeleteCollectWithParameters:dict success:^(id response) {
                //更新数据
                [weakSelf dataRequestDetailAction];
            } failure:^(NSDictionary *error) {
                //更新数据
                [weakSelf dataRequestDetailAction];
            }];
        }

    }
}
#pragma mark -- 跳转到购物车
- (void)jumpToShopCarAction{
    [self.tabBarController setSelectedIndex:1];
}
#pragma mark -- 添加到购物车
- (void)addShopToShopCarAction{
    _bugGoodsOrAddShop = 1;
    
    if (self.typeView.goodsTypeArr.count) {
        [self.typeView show];
    }else {
        [self requestAddShopCarAction];
    }
}

- (void)requestAddShopCarAction {
    NSString *tokenStr = [QJUserInfo getToken];
    if (tokenStr.length < 1) {
        [MBPHUD showAlertWithTitle:@"请先登录您的账号!"];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];;
        return;
    }
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.detailDic[@"shopid"] forKey:@"shopid"];
    [dict setObject:self.detailDic[@"id"] forKey:@"goodsid"];
    [dict setObject:@(self.buyCount) forKey:@"amount"];
    [dict setObject:[self requestSpecificationsString] forKey:@"goodsSpecificationsId"];
    
    [WWNetRequest fetchAddCartWithParameters:dict success:^(id response) {
        [MBPHUD showAlertWithTitle:@"商品已加入购物车!"];
       
    } failure:^(NSDictionary *error) {
    }];
    
}


- (void)buyGoodsAction{
    _bugGoodsOrAddShop = 0;
    
    if (self.typeView.goodsTypeArr.count) {
        [self.typeView show];
    }else {
        [self requestBuyGoodsAction];
    }
    
}

- (void)requestBuyGoodsAction {
    NSString *tokenStr = [QJUserInfo getToken];
    if (tokenStr.length < 1) {
        [MBPHUD showAlertWithTitle:@"请先登录您的账号!"];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
        return;
    }

    
    if ([_selectedModel.store_count isEqualToString:@"0"]) {
        
        [MBPHUD showAlertWithTitle:@"该商品没有库存"];
        
        return;
    }
    
    QJPreviewOrderVC *VC = [[QJPreviewOrderVC alloc]init];
    VC.orderType = @"2";
    VC.orderGoodsid = [NSString stringWithFormat:@"%@", self.detailDic[@"goods_id"]];
    VC.amountStr = [NSString stringWithFormat:@"%d", self.buyCount];
    VC.specificationsString = [self requestSpecificationsString];
    
    KPushViewControllerAction(VC);
    
}



#pragma mark - 拼接规格
- (NSString *)requestSpecificationsString {
    // 拼接规格
    NSString *str = @"";
    for (int i = 0; i<self.typeView.selectedArr.count; i++) {
        
        YFGoodsTypeSubModel *model = self.typeView.selectedArr[i];
        
        if (i == 0) {
            str = [str stringByAppendingString:model.item_id];
        }else {
            str = [str stringByAppendingString:[NSString stringWithFormat:@"_%@", model.item_id]];
        }
    }
    for (YFGoodsPriceModel *subModel in self.typeView.goodsPriceArr) {
        
        if ([subModel.key isEqualToString:str]) {
            str = subModel.item_id;
        }
    }
    return str;
}

#pragma mark -- Event Response
- (void)collectionBtnClick:(UIButton *)btn { // 收藏
    
    //判断是否登录
    NSString *token = [QJUserInfo getToken];
    if (!token) {
        [MBPHUD showAlertWithTitle:@"请先登录您的账号!"];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        KPushViewControllerAction(VC);
        return;
    }
    
    // 改变选中状态
    BOOL newState = btn.selected ? NO : YES;
    
    [self updateCollectionState:newState];
}

- (void)updateCollectionState:(BOOL)select { // 更新收藏状态
    // 网络请求
    if (self.detailDic) {
        
        
        WEAKSELF
        if (select) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObject:self.detailDic[@"goods_id"] forKey:@"goods_ids"];

            [WWNetRequest fetchAddCollectWithParameters:dict success:^(id response) {
                self.collectionBtn.selected = YES;
            } failure:^(NSDictionary *error) {
                NSLog(@"添加收藏 error = %@", error);
            }];
        }else{
            
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setObject:self.detailDic[@"goods_id"] forKey:@"id"];
            
            [WWNetRequest fetchDeleteCollectWithParameters:dict success:^(id response) {
                self.collectionBtn.selected = NO;
            } failure:^(NSDictionary *error) {
                NSLog(@"取消收藏 error = %@", error);
                
            }];
        }
    }
}

- (void)shareBtnClick { // 分享
    
}

#pragma mark - 加入购物车
- (void)shoppingCartBtnClick {
    NSString *tokenStr = [QJUserInfo getToken];
    if (tokenStr.length < 1) {
        [MBPHUD showAlertWithTitle:@"请先登录您的账号!"];
        QJLoginVC *VC = [[QJLoginVC alloc]init];
        [self.navigationController pushViewController:VC animated:YES];;
        return;
    }
    if (self.hasAttribute) {  // 有规格属性  // 点击提示弹框
        
        if (self.typeView.selectedArr.count == 0) { // 没有选中规格属性, 接着弹框
            [MBPHUD showAlertWithTitle:@"请选择商品属性"];
        }else {  // 选中规格属性, 加入购物车
            [self requestAddShoppingCart];
        }
        
        
    }else {  // 没有规格属性
        [self requestAddShoppingCart];
    }
}

// 加入购物车 网络请求, 新接口
- (void)requestAddShoppingCart {
    /*
     "    `goods_id` 商品ID
     "    goods_num  数量
     "    item_id 规则ID累加 格式为11_56
     */
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    if (self.hasAttribute) {
        [dict setObject:[self requestSpecificationsString] forKey:@"item_id"];
//        [dict setObject:self.selectedModel.key forKey:@"item_id"];
        [dict setObject:@(self.buyCount) forKey:@"goods_num"];
        [dict setObject:self.detailDic[@"goods_id"] forKey:@"goods_id"];
        NSLog(@"key = %@, item_id = %@, count = %ld", self.selectedModel.key, self.selectedModel.item_id, (long)self.shopVC.buyCount);
    }else {
        NSLog(@"detailDic.goods_id = %@", self.detailDic[@"goods_id"]);
        [dict setObject:@"" forKey:@"item_id"];
        [dict setObject:@(1) forKey:@"goods_num"]; // 没有属性,加入购物车,默认就是1
        [dict setObject:self.detailDic[@"goods_id"] forKey:@"goods_id"];
    }

    /*
     2018-05-18 10:54:23.096 QuanJieShopProject[18910:16839223] key = (null), item_id = (null), count = 0
     */
    [WWNetRequest fetchAddCartWithParameters:dict success:^(id response) {
        
        NSLog(@"response = %@", response);
        
        [MBPHUD showAlertWithTitle:@"成功加入购物车!"];
        
    } failure:^(NSDictionary *error) {
        
    }];
}

#pragma mark -- 立即购买
- (void)buyBtnClick {
    
    _bugGoodsOrAddShop = 0;
    
    NSLog(@"goodsTypeArr.count = %d", self.typeView.goodsTypeArr.count);
    NSLog(@"goodsTypeArr = %@", self.typeView.goodsTypeArr);
    
    if (self.hasAttribute) { // 有规格属性
        if (self.typeView.selectedArr.count == 0) { // 没有选中规格属性, 接着弹框
            [MBPHUD showAlertWithTitle:@"请选择商品属性"];
        }else {  // 选中规格属性, 跳转
            [self requestBuyGoodsAction];
        }
        
    }else {  // 没有规格属性,直接弹框,选数目
        [self.typeView show];
    }
    
//    if (self.typeView.goodsTypeArr.count == 0) { // 有规格属性, 就弹框
//        [self.typeView show];
//    }else {  // 没有规格属性, 订单预览界面
//        [self requestBuyGoodsAction];
//    }
    
}

#pragma mark - 懒加载
- (UIView *)bottomView {
    if (!_bottomView) {
        
        CGFloat bottomViewH = 100.f/1334.f * UISCREEN_HEIGHT;
        CGFloat bottomViewY = UISCREEN_HEIGHT - bottomViewH;
        UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, bottomViewY, UISCREEN_WIDTH, bottomViewH)];
        bottomView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bottomView];
        [self.view bringSubviewToFront:bottomView];
        _bottomView = bottomView;
        
        // 收藏
        UIButton *collectionBtn = [[UIButton alloc] init];
        [collectionBtn setTitle:@"收藏" forState:UIControlStateNormal];
        [collectionBtn setTitleColor:YFColor_Text forState:UIControlStateNormal];
        [collectionBtn addTarget:self action:@selector(collectionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [collectionBtn setImage:[UIImage imageNamed:@"collection"] forState:UIControlStateNormal];
        [collectionBtn setImage:[UIImage imageNamed:@"collectionSelected"] forState:UIControlStateSelected];
        collectionBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [_bottomView addSubview:collectionBtn];
        self.collectionBtn = collectionBtn;
        
        // 分享
        UIButton *shareBtn = [[UIButton alloc] init];
        [shareBtn setTitle:@"分享" forState:UIControlStateNormal];
        [shareBtn setTitleColor:YFColor_Text forState:UIControlStateNormal];
        [shareBtn addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [shareBtn setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
        shareBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [_bottomView addSubview:shareBtn];
        self.shareBtn = shareBtn;
        
        // 立即购买
        UIButton *buyBtn = [[UIButton alloc] init];
        [buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
        [buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [buyBtn addTarget:self action:@selector(buyBtnClick) forControlEvents:UIControlEventTouchUpInside];
        buyBtn.backgroundColor = YFColor_Red;
        buyBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_bottomView addSubview:buyBtn];
        
        // 加入购物车
        UIButton *shoppingCartBtn = [[UIButton alloc] init];
        [shoppingCartBtn setTitle:@"加入购物车" forState:UIControlStateNormal];
        [shoppingCartBtn setTitleColor:[UIColor colorWithHexString:@"aaaaaa"] forState:UIControlStateNormal];
        [shoppingCartBtn addTarget:self action:@selector(shoppingCartBtnClick) forControlEvents:UIControlEventTouchUpInside];
        shoppingCartBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_bottomView addSubview:shoppingCartBtn];
        
        UIView *topLine = [[UIView alloc] init];
        topLine.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
        [_bottomView addSubview:topLine];
        
        UIView *paddingLine = [[UIView alloc] init];
        paddingLine.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
        [_bottomView addSubview:paddingLine];
        
        // 添加约束
        [collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(_bottomView);
            make.width.height.equalTo(_bottomView.mas_height);
        }];
        
        [paddingLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0.5));
            make.height.equalTo(collectionBtn.mas_height).with.multipliedBy(0.8);
            make.left.equalTo(collectionBtn.mas_right);
            make.centerY.equalTo(collectionBtn.mas_centerY);
        }];
        
        [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_bottomView);
            make.left.equalTo(paddingLine.mas_right);
            make.width.height.equalTo(_bottomView.mas_height);
        }];
        
        [buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.height.equalTo(_bottomView);
            make.width.equalTo(_bottomView).with.multipliedBy(200.f/750.f);
        }];
        
        [shoppingCartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(_bottomView);
            make.right.equalTo(buyBtn.mas_left);
            make.width.equalTo(_bottomView).with.multipliedBy(240.f/750.f);
        }];
        
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.left.top.equalTo(_bottomView);
            make.height.equalTo(@(0.5));
        }];
        
    }
    return _bottomView;
}



- (YFGoodsTypeView *)typeView {
    if (!_typeView) {
        YFGoodsTypeView *typeView = [[YFGoodsTypeView alloc] initWithFrame:self.view.bounds];
        
        WEAKSELF
        typeView.confirmBlock = ^(YFGoodsPriceModel *model, NSArray *selectedArr, NSInteger buyCount) {
            weakSelf.buyCount = buyCount;
            weakSelf.selectedModel = model;
            NSLog(@"item_id=%@, key=%@", model.item_id, model.key);
            
            if (self.hasAttribute) { // 有属性,就只是确认按钮,什么都不搞
                // 更新界面
                YFShopDetailCellModel *detailModel = weakSelf.shopVC.dataSourceArr[1];
                detailModel.title = @"规格";

                NSString *str = @"";
                for (int i = 0; i < selectedArr.count; i++) {
                    YFGoodsTypeSubModel *model = selectedArr[i];
                    if (i == 0) {
                        str = [str stringByAppendingString:model.item];
                    }else {
                        str = [str stringByAppendingString:[NSString stringWithFormat:@",%@", model.item]];
                    }
                }
                detailModel.datail = str;
                [weakSelf.shopVC reload];
                
            }else {  // 没有属性直接购买, 因为没属性,点加入购物车不弹框,默认数目1
                [self requestBuyGoodsAction];
            }
            
        };
        
        [self.view addSubview:typeView];
        _typeView = typeView;
    }
    return _typeView;
}















@end

